﻿
Imports Business
Imports System.Globalization

Public Class frmHoliday

    Dim bsOrganization As BSOrganization

    Dim bsHoliday As BSHoliday

    Dim dtHoliday As DataTable

    Dim dtHolidayRegular As DataTable
    
    Dim dtOrgan As Data.DataTable

    Dim years As Object() = New Object() {"2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020"}

    Dim months As Object() = New Object() {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}

    'dim nameDayOfWeek As Object() = New Object() {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}

    Dim strSunday As String = "Sunday"

    Dim strMonday As String = "Monday"

    Dim strTuesday As String = "Tuesday"

    Dim strWednesday As String = "Wednesday"

    Dim strThursday As String = "Thursday"

    Dim strFriday As String = "Friday"

    Dim strSaturday As String = "Saturday"

    Dim yearFrom As Integer = 2000

    Dim yearTo As Integer = 2020

    Private scolDate As String = "Date"

    Private scolRemark As String = "Remarks"

    Private scolDateDB As String = "DateDB"

    ''' <summary>
    ''' optional
    ''' </summary>
    ''' <remarks></remarks>
    Dim flagOptional As Boolean

    Dim flagRegular As Boolean


    Public Sub New(ByVal serverName As String)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        cboYear.Items.AddRange(years)
        cboYear.SelectedIndex = 0

        cboMonth.Items.AddRange(months)
        cboMonth.SelectedIndex = 0

        LoadCboDay()

        bsHoliday = New BSHoliday(serverName)

        dtHoliday = New DataTable()

        dtHolidayRegular = New DataTable()

        dtHolidayRegular.Columns.Add(scolDateDB)
        dtHolidayRegular.Columns.Add(scolRemark)

        bsOrganization = New BSOrganization(serverName)

        ' get datatable all organization
        dtOrgan = bsOrganization.GetOrganization()

        frmCompanyDepartment.LoadTreeOrgan(dtOrgan, trvOrgan)

        trvOrgan.ExpandAll()

        cboDayOfWeek.Items.Add(strSunday)
        cboDayOfWeek.Items.Add(strMonday)
        cboDayOfWeek.Items.Add(strTuesday)
        cboDayOfWeek.Items.Add(strWednesday)
        cboDayOfWeek.Items.Add(strThursday)
        cboDayOfWeek.Items.Add(strFriday)
        cboDayOfWeek.Items.Add(strSaturday)

        cboDayOfWeek.SelectedIndex = 0

        ' Template column
        Dim cell As DataGridViewCell = New DataGridViewTextBoxCell()

        ' add column Date  
        Dim colDate As DataGridViewColumn = New DataGridViewColumn
        colDate.HeaderText = scolDate
        colDate.Name = scolDate
        colDate.CellTemplate = cell
        grdHoliday.Columns.Add(colDate)

        ' add column remark 
        Dim colRemark As DataGridViewColumn = New DataGridViewColumn
        colRemark.HeaderText = scolRemark
        colRemark.Name = scolRemark
        colRemark.CellTemplate = cell
        grdHoliday.Columns.Add(colRemark)

        ' add column Date yyyyMMdd  
        Dim colDateDB As DataGridViewColumn = New DataGridViewColumn
        colDateDB.HeaderText = scolDateDB
        colDateDB.Name = scolDateDB
        colDateDB.CellTemplate = cell
        ' hide column
        colDateDB.Visible = False
        grdHoliday.Columns.Add(colDateDB)

        'grdDate.Columns.Add(strSunday, strSunday)
        'grdDate.Columns.Add(strMonday, strMonday)
        'grdDate.Columns.Add(strTuesday, strTuesday)
        'grdDate.Columns.Add(strWednesday, strWednesday)
        'grdDate.Columns.Add(strThursday, strThursday)
        'grdDate.Columns.Add(strFriday, strFriday)
        'grdDate.Columns.Add(strSaturday, strSaturday)

        'For i As Integer = 0 To grdDate.Columns.Count-1

        '    grdDate.Columns.Item(i).SortMode = DataGridViewColumnSortMode.NotSortable

        '    grdDate.Columns.Item(i).AutoSizeMode = DataGridViewAutoSizeColumnsMode.Fill

        'Next



    End Sub

    ''' <summary>
    ''' load event
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub frmHoliday_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        LoadGridHoliday()


        'grdDate.ClearSelection()

    End Sub


    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub cboMonth_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboMonth.SelectedIndexChanged

        If Not String.IsNullOrEmpty(cboYear.Text) Then

            LoadCboDay()

        End If

        LoadGridHoliday()

    End Sub


    ''' <summary>
    ''' Load grid holiday in 1 month
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub LoadGridHoliday()

        If Not trvOrgan.SelectedNode Is Nothing Then

            ' get month
            Dim month As Integer = Integer.Parse(cboMonth.Text)

            ' get year
            Dim year As Integer = Integer.Parse(cboYear.Text)

            ' get organ no
            Dim organNo As String = trvOrgan.SelectedNode.Name

            ' get data holiday in month
            dtHoliday = bsHoliday.GetHoliday(organNo, month, year)

            ' clear row in gridview holiday
            grdHoliday.Rows.Clear()

            If Not dtHoliday Is Nothing Then

                Dim gridViewRow As DataGridViewRow

                For Each row As DataRow In dtHoliday.Rows

                    gridViewRow = New DataGridViewRow

                    Dim cell As DataGridViewCell = New DataGridViewTextBoxCell()

                    ' cell date
                    Dim d As DateTime = DateTime.ParseExact(Business.Functions.ConvertstrDBDateToStrDate(row.Item("HOLIDAY_DATE")),
                                        "d", New CultureInfo("fr-FR"))

                    cell.Value = d.ToString("dd/MM/yyyy(ddddd)")

                    gridViewRow.Cells.Add(cell)

                    ' cell remark
                    cell = New DataGridViewTextBoxCell()

                    If Not row.Item("REMARKS").Equals(DBNull.Value) Then

                        cell.Value = row.Item("REMARKS")

                    Else

                        cell.Value = ""

                    End If

                    gridViewRow.Cells.Add(cell)

                    ' cell date database
                    cell = New DataGridViewTextBoxCell()

                    cell.Value = row.Item("HOLIDAY_DATE")

                    gridViewRow.Cells.Add(cell)

                    ' add row to datagridview
                    grdHoliday.Rows.Add(gridViewRow)

                Next

            End If

            grdHoliday.ClearSelection()

            ' clear flag
            flagOptional = False
            flagRegular = False

        End If
        
    End Sub


    'Private Sub LoadGridDate()

    '    ' get month
    '    Dim month As Integer = Integer.Parse(cboMonth.Text)

    '    ' get year
    '    Dim year As Integer = Integer.Parse(cboYear.Text)

    '    ' get number of day in month
    '    Dim numOfDay As Integer = Date.DaysInMonth(year, month)

    '    Dim firstDate As Date = New Date(year, month, 1)

    '    Dim cell As DataGridViewCell

    '    Dim row As DataGridViewRow

    '    If firstDate.DayOfWeek = DayOfWeek.Sunday Then

    '        cell = New DataGridViewTextBoxCell()

    '        row = New DataGridViewRow()

    '        cell.Value = 1

    '        row.Cells.Add(cell)

    '    ElseIf firstDate.DayOfWeek = DayOfWeek.Monday Then

    '        row = New DataGridViewRow()

    '        cell = New DataGridViewTextBoxCell()

    '        cell.Value = ""

    '        row.Cells.Add(cell)

    '        cell = New DataGridViewTextBoxCell()

    '        cell.Value = 1

    '        row.Cells.Add(cell)

    '    ElseIf firstDate.DayOfWeek = DayOfWeek.Tuesday Then

    '        row = New DataGridViewRow()

    '        AddCellToRow(2, row)

    '        cell = New DataGridViewTextBoxCell()

    '        cell.Value = 1

    '        row.Cells.Add(cell)


    '    ElseIf firstDate.DayOfWeek = DayOfWeek.Wednesday Then

    '        row = New DataGridViewRow()

    '        AddCellToRow(3, row)

    '        cell = New DataGridViewTextBoxCell()

    '        cell.Value = 1

    '        row.Cells.Add(cell)

    '    ElseIf firstDate.DayOfWeek = DayOfWeek.Thursday Then

    '        row = New DataGridViewRow()

    '        AddCellToRow(4, row)

    '        cell = New DataGridViewTextBoxCell()

    '        cell.Value = 1

    '        row.Cells.Add(cell)

    '    ElseIf firstDate.DayOfWeek = DayOfWeek.Friday Then

    '        row = New DataGridViewRow()

    '        AddCellToRow(5, row)

    '        cell = New DataGridViewTextBoxCell()

    '        cell.Value = 1

    '        row.Cells.Add(cell)

    '    ElseIf firstDate.DayOfWeek = DayOfWeek.Saturday Then

    '        row = New DataGridViewRow()

    '        AddCellToRow(6, row)

    '        cell = New DataGridViewTextBoxCell()

    '        cell.Value = 1

    '        row.Cells.Add(cell)

    '    End If

    '    grdDate.Rows.Add(row)

    'End Sub


    'Private Sub AddCellToRow(ByVal n As Integer, ByRef gridViewRow As DataGridViewRow)

    '    Dim cell As DataGridViewCell

    '    For j As Integer = 0 To n - 1

    '        cell = New DataGridViewTextBoxCell()

    '        cell.Value = ""

    '        gridViewRow.Cells.Add(cell)

    '    Next

    'End Sub

    'Private Sub AddRow(ByVal i As Integer, ByVal firstDate As Date)

    '    Dim d As Date = firstDate.AddDays(i)




    'End Sub


    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub txtStartDate_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStartDate.Enter

        'check if string text in textbox is different null 
        If Not String.IsNullOrWhiteSpace(txtStartDate.Text) Then

            ' convert string date to integer data
            txtStartDate.Text = ConvertStrDateToInt(txtStartDate.Text)

        End If

    End Sub




    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub txtStartDate_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStartDate.Leave

        If Not String.IsNullOrWhiteSpace(txtStartDate.Text) And txtStartDate.Text.Length >= 7 Then

            ' validate year, month, day
            If Functions.ValidateStrDate(Double.Parse(txtStartDate.Text.Trim()).ToString("0#/##/####"), yearFrom, yearTo) Then

                If Not String.IsNullOrEmpty(txtEndDate.Text) Then

                    If DateTime.ParseExact(Double.Parse(txtStartDate.Text.Trim()).ToString("0#/##/####"), "d", New CultureInfo("fr-FR")) _
                        < DateTime.ParseExact(txtEndDate.Text, "d", New CultureInfo("fr-FR")) Then

                        '  set value to textbox
                        txtStartDate.Text = Double.Parse(txtStartDate.Text).ToString("0#/##/####")

                        'set normal message
                        lblMessage.Text = Nothing

                    Else

                        ' false clear value
                        txtStartDate.Text = Nothing

                        ' print error message
                        lblMessage.Text = "Start Date < End Date"

                    End If

                Else

                    '  set value to textbox
                    txtStartDate.Text = Double.Parse(txtStartDate.Text).ToString("0#/##/####")

                    'set normal message
                    lblMessage.Text = Nothing

                End If


            Else

                ' false clear value
                txtStartDate.Text = Nothing

                ' print error message
                lblMessage.Text = "Start Date is not valid"

            End If
        Else

            ' false clear value
            txtStartDate.Text = Nothing

        End If

    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub txtStartDate_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtStartDate.KeyPress

        ' limit length of text less than 8 letters
        txtStartDate.MaxLength = 8

        ' check only allow numeric
        If (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then

            e.Handled = False

        Else
            ' cancel
            e.Handled = True

        End If


    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub txtEndDate_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEndDate.Enter

        'check if string text in textbox is different null 
        If Not String.IsNullOrWhiteSpace(txtEndDate.Text) Then

            ' convert string date to integer data
            txtEndDate.Text = ConvertStrDateToInt(txtEndDate.Text)

        End If

    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub txtEndDate_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEndDate.Leave

        If Not String.IsNullOrWhiteSpace(txtEndDate.Text) And txtEndDate.Text.Length >= 7 Then

            ' validate year, month, day
            If Business.Functions.ValidateStrDate(Double.Parse(txtEndDate.Text.Trim()).ToString("0#/##/####"), yearFrom, yearTo) Then

                If Not String.IsNullOrEmpty(txtStartDate.Text) Then

                    If DateTime.ParseExact(Double.Parse(txtEndDate.Text.Trim()).ToString("0#/##/####"), "d", New CultureInfo("fr-FR")) _
                        > DateTime.ParseExact(txtStartDate.Text, "d", New CultureInfo("fr-FR")) Then

                        ' set value to textbox
                        txtEndDate.Text = Double.Parse(txtEndDate.Text).ToString("0#/##/####")

                        'set normal message
                        lblMessage.Text = Nothing
                    Else

                        ' false, clear value
                        txtEndDate.Text = Nothing

                        ' print error message
                        lblMessage.Text = "End date > Start date"
                    End If

                Else

                    ' set value to textbox
                    txtEndDate.Text = Double.Parse(txtEndDate.Text).ToString("0#/##/####")

                    'set normal message
                    lblMessage.Text = Nothing

                End If


            Else

                ' false clear value
                txtEndDate.Text = Nothing

                ' print error message
                lblMessage.Text = "End date is not valid"

            End If
        Else

            ' false clear value
            txtEndDate.Text = Nothing

        End If

    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub txtEndDate_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtEndDate.KeyPress

        ' limit length of text less than 8 letters
        txtEndDate.MaxLength = 8

        ' check only allow numeric
        If (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then

            e.Handled = False

        Else
            ' cancel
            e.Handled = True

        End If


    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub trvOrgan_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles trvOrgan.AfterSelect

        LoadGridHoliday()

    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub cboYear_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboYear.SelectedIndexChanged

        If Not String.IsNullOrEmpty(cboMonth.Text) Then

            LoadCboDay()

        End If

        LoadGridHoliday()

    End Sub


    ''' <summary>
    ''' Add holiday optional
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        If Not trvOrgan.SelectedNode Is Nothing Then

            Dim isExisted As Boolean = False

            Dim dayDB As String = cboYear.Text & Integer.Parse(cboMonth.Text).ToString("00") & Integer.Parse(cboDay.Text).ToString("00")

            ' check in datagridview
            For i As Integer = 0 To grdHoliday.Rows.Count - 1

                If grdHoliday.Rows.Item(i).Cells.Item(scolDateDB).Value.ToString().Equals(dayDB) Then

                    ' set message duplicated
                    lblMessage.Text = "Holiday date is existed."

                    isExisted = True

                    Exit For

                End If

            Next

            If Not isExisted Then

                Dim gridViewRow As DataGridViewRow = New DataGridViewRow()

                Dim cell As DataGridViewCell = New DataGridViewTextBoxCell()

                ' cell date
                Dim d As DateTime = DateTime.ParseExact(Business.Functions.ConvertstrDBDateToStrDate(dayDB),
                                            "d", New CultureInfo("fr-FR"))

                cell.Value = d.ToString("dd/MM/yyyy(ddddd)")

                gridViewRow.Cells.Add(cell)

                ' cell remark
                cell = New DataGridViewTextBoxCell()

                If Not String.IsNullOrEmpty(txtRemark2.Text) Then

                    cell.Value = txtRemark2.Text

                Else

                    cell.Value = ""

                End If

                gridViewRow.Cells.Add(cell)

                ' cell date database
                cell = New DataGridViewTextBoxCell()

                cell.Value = dayDB

                gridViewRow.Cells.Add(cell)

                ' add row to datagridview
                grdHoliday.Rows.Add(gridViewRow)

                ' clear value remark
                txtRemark2.Text = Nothing

                cboDay.SelectedIndex = 0

                flagOptional = True

            End If


        End If

    End Sub




    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click

        If grdHoliday.SelectedRows.Count > 0 Then

            grdHoliday.Rows.Remove(grdHoliday.SelectedRows.Item(0))

            flagOptional = True

        End If

    End Sub

    ''' <summary>
    ''' Update holiday
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

        lblMessage.Text = "Working..."

        Application.DoEvents()

        ' optional holiday
        If flagOptional Then

            ' delete holiday in dtholiday
            For Each row As DataRow In dtHoliday.Rows

                bsHoliday.DeleteHoliday(trvOrgan.SelectedNode.Name, row.Item("HOLIDAY_DATE"))

            Next

            Dim flag As Boolean

            ' insert holiday
            For i As Integer = 0 To grdHoliday.Rows.Count - 1

                If Not bsHoliday.InsertHoliday(trvOrgan.SelectedNode.Name, grdHoliday.Rows.Item(i).Cells.Item(scolDateDB).Value,
                                           grdHoliday.Rows.Item(i).Cells.Item(scolRemark).Value) Then

                    flag = True

                End If

            Next

            If flag Then

                'print error message update error
                lblMessage.Text = "Update error."

            Else

                lblMessage.Text = "Update is successful."

            End If
            
        End If

        ' regular holiday
        If flagRegular Then

            ' delete holiday in dtholiday
            For Each row As DataRow In dtHolidayRegular.Rows

                bsHoliday.DeleteHoliday(trvOrgan.SelectedNode.Name, row.Item(scolDateDB))

            Next

            Dim flag As Boolean

            ' insert holiday
            For Each row As DataRow In dtHolidayRegular.Rows

                If Not bsHoliday.InsertHoliday(trvOrgan.SelectedNode.Name, row.Item(scolDateDB), row.Item(scolRemark)) Then

                    flag = True

                End If

            Next


            If flag Then

                'print error message update error
                lblMessage.Text = "Update error."

            Else

                LoadGridHoliday()

                lblMessage.Text = "Update is successful."

            End If


        End If

        Application.DoEvents()
       

    End Sub

    ''' <summary>
    ''' set regular holiday
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSet.Click

        If Not String.IsNullOrEmpty(txtStartDate.Text) And Not String.IsNullOrEmpty(txtEndDate.Text) Then

            ' start date
            Dim startDate As DateTime = DateTime.ParseExact(txtStartDate.Text,
                                        "d", New CultureInfo("fr-FR"))

            'end date
            Dim endDate As DateTime = DateTime.ParseExact(txtEndDate.Text,
                                        "d", New CultureInfo("fr-FR"))

            ' get holiday set
            If cboDayOfWeek.Text.Equals(strSunday) Then

                AddHolidayRegular(startDate, endDate, DayOfWeek.Sunday)

            ElseIf cboDayOfWeek.Text.Equals(strSaturday) Then

                AddHolidayRegular(startDate, endDate, DayOfWeek.Saturday)

            ElseIf cboDayOfWeek.Text.Equals(strFriday) Then

                AddHolidayRegular(startDate, endDate, DayOfWeek.Friday)

            ElseIf cboDayOfWeek.Text.Equals(strThursday) Then

                AddHolidayRegular(startDate, endDate, DayOfWeek.Thursday)

            ElseIf cboDayOfWeek.Text.Equals(strWednesday) Then

                AddHolidayRegular(startDate, endDate, DayOfWeek.Wednesday)

            ElseIf cboDayOfWeek.Text.Equals(strTuesday) Then

                AddHolidayRegular(startDate, endDate, DayOfWeek.Tuesday)

            ElseIf cboDayOfWeek.Text.Equals(strMonday) Then

                AddHolidayRegular(startDate, endDate, DayOfWeek.Monday)

            End If

            flagRegular = True

            ' set message 
            lblMessage.Text = "Set regular holiday."
            
        End If

    End Sub


    ''' <summary>
    ''' add holiday regular to dtHolidayRegular
    ''' </summary>
    ''' <param name="startDate"></param>
    ''' <param name="endDate"></param>
    ''' <param name="dayOfWeek"></param>
    ''' <remarks></remarks>
    Private Sub AddHolidayRegular(ByVal startDate As DateTime, ByVal endDate As DateTime, ByVal dayOfWeek As DayOfWeek)

        ' check date and add to 
        Dim d As DateTime = startDate

        ' clear all date exist in the previous holiday
        dtHolidayRegular.Rows.Clear()

        While d <= endDate

            If d.DayOfWeek = dayOfWeek Then

                dtHolidayRegular.Rows.Add(d.ToString("yyyyMMdd"), txtRemark1.Text)

            End If

            d = d.AddDays(1)

        End While

    End Sub


    ''' <summary>
    ''' Load combobox day
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub LoadCboDay()

        For i As Integer = 1 To Date.DaysInMonth(Integer.Parse(cboYear.Text), Integer.Parse(cboMonth.Text))

            cboDay.Items.Add(i)

        Next

        cboDay.SelectedIndex = 0

    End Sub
    

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click

        frmMain.RemoveTabpage()

    End Sub

End Class